package com.dnjn.mes.biz.controller;

import com.dnjn.mes.biz.enums.DataType;
import com.dnjn.mes.biz.modbus.ModbusMasterHelper;
import com.dnjn.mes.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/modbus")
public class ModbusController {
    public enum RegisterAddrType {
        Coil, HoldingRegister, DiscreteInput, InputRegister
    }

    @Autowired
    private ModbusMasterHelper modbusMasterHelper;


    @GetMapping("/{type}/{offset}/{dataType}")
    public AjaxResult get(@PathVariable RegisterAddrType type, @PathVariable int offset,
                          @PathVariable DataType dataType) {

        Number num = modbusMasterHelper.readHoldingRegister(1, offset, dataType);
        return AjaxResult.success(num);
    }
}
